<?php
$uid = yii::app()->user->id;
$items = yii::app()->user->getState($uid);
$quantity = yii::app()->user->getState('quantity');
$model = new Item();
?>
<div class="row">
    <div class="twelve columns">
        <div class="left">
        <h1>My Shopping Cart</h1>
        </div>
        <div class="right" id="buyall">
                <?php if($items != NULL){ ?>
            
            <form class="nice" action="<?php echo $this->createUrl('item/buyall', array('items' => $items)) ?>">

                <?php
                echo CHtml::submitButton('Buy All', array(
                'class' => 'nice blue radius button'
                ));
                ?>

        </form>
                
            <?php }?>
        </div>
        <hr>
        <ul class="block-grid mobile four-up">


<?php
if($items != NULL)
{
foreach($items as &$value)
{
     $model = Item::model()->findByPk($value);
     $modelq = $model->quantity;
     $itemquantity = $quantity[$value];
     $itemprice = $model->price * $quantity[$value];

?>

        <li class="shop-item">
            <h2><?php echo CHtml::link($model->name, array('item/view', 'id' => $model->id)) ?></h2>
            <?php echo CHtml::link(CHtml::image(Yii::app()->baseUrl . "/uploads/thumbnails/$model->id.jpg"), array('item/view', 'id' => $model->id)) ?>
            <p><?php echo CHtml::encode($model->description); ?></p>

            <b><?php echo CHtml::encode($model->getAttributeLabel('quantity')); ?>:</b>
            <?php echo CHtml::encode($itemquantity); ?>,
            <b><?php echo CHtml::encode($model->getAttributeLabel('price')); ?>:</b>
            $<?php echo CHtml::encode($itemprice); ?>
            <br />
            <span><?php echo CHtml::link("View User's Shop", array('user/view', 'id' => $model->user_id)) ?></span>
            <form class="nice" action="<?php echo $this->createUrl('user/DeleteCart', array('id' => $model->id)) ?>">
            <?php
            echo CHtml::submitButton('Delete from Cart', array(
            'class' => 'nice red radius button'
                        ));
            ?>
            </form>
        </li>

<?php
}
}
?>
        </ul>
    </div>
</div>